home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 May / macformat-024.iso / Shareware City / Developers / Kant Pro source Folder / Kant Pro 1.1 ƒ / kode new / kant build window.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-19  |  6.2 KB  |  265 lines  |  [TEXT/MMCC]

  1. #include "kant build window.h"
  2. #include "kant build meat.h"
  3. #include "kant build gui.h"
  4. #include "kant build files.h"
  5. #include "kant load-save.h"
  6. #include "environment.h"
  7. #include "util.h"
  8. #include "menus.h"
  9. #include "main.h"
  10. #include "dialogs.h"
  11. #include "text twiddling.h"
  12. #include "generic window handlers.h"
  13. #include "window layer.h"
  14. #include "program globals.h"
  15.  
  16. #define kGrowBoxSize        15
  17.  
  18. enum { key_LeftArrow=0x1c, key_RightArrow, key_UpArrow, key_DownArrow };
  19.  
  20. static    void PutDataIntoTEFields(WindowPtr theWindow);
  21.  
  22. static    TEClickLoopUPP    gClickLoopUPP;
  23. static    Boolean            gSetupDone=FALSE;
  24.  
  25. void SetupTheBuildWindow(WindowPtr theWindow)
  26. {
  27.     unsigned char    *titleStr="\puntitled";
  28.     Point            topLeft;
  29.     FSSpec            fs;
  30.     
  31.     SetWindowHeight(theWindow, qd.screenBits.bounds.bottom-qd.screenBits.bounds.top-LMGetMBarHeight()-48);
  32.     SetWindowWidth(theWindow, qd.screenBits.bounds.right-qd.screenBits.bounds.left-70);
  33.     SetWindowType(theWindow, zoomDocProc);
  34.     topLeft.v=qd.screenBits.bounds.top+LMGetMBarHeight()+40;
  35.     topLeft.h=qd.screenBits.bounds.left+30;
  36.     SetWindowTopLeft(theWindow, topLeft);
  37.     SetWindowHasCloseBox(theWindow, TRUE);
  38.     SetWindowMaxDepth(theWindow, 1);
  39.     SetWindowDepth(theWindow, 1);
  40.     SetWindowIsFloat(theWindow, FALSE);
  41.     SetWindowTitle(theWindow, titleStr);
  42.     SetWindowAutoCenter(theWindow, FALSE);
  43.     fs.name[0]=0x00;
  44.     fs.vRefNum=0;
  45.     fs.parID=0;
  46.     SetWindowFS(theWindow, fs);
  47.     SetWindowIsModified(theWindow, FALSE);
  48.     
  49.     if (gSetupDone)
  50.         return;
  51.     
  52.     gClickLoopUPP=NewTEClickLoopProc(MyClikLoop);
  53.     gSetupDone=TRUE;
  54.     gNeedToOpenWindow=FALSE;
  55. }
  56.  
  57. void ShutDownTheBuildWindow(void)
  58. {
  59.     if (gClickLoopUPP!=0L)
  60.         DisposeRoutineDescriptor(gClickLoopUPP);
  61. }
  62.  
  63. void OpenTheBuildWindow(WindowPtr theWindow)
  64. {
  65.     TEHandle        hTE;
  66.     FontInfo        theFontInfo;
  67.     Rect            vScrollBarRect, hScrollBarRect;
  68.     Rect            destRect, viewRect;
  69.     
  70.     hTE=GetWindowTE(theWindow);
  71.     if (hTE==0L)
  72.     {
  73.         SetRect(&vScrollBarRect, GetWindowWidth(theWindow)-kGrowBoxSize, -1,
  74.             GetWindowWidth(theWindow)+1, GetWindowHeight(theWindow)+1-kGrowBoxSize);
  75.         SetRect(&hScrollBarRect, -1, GetWindowHeight(theWindow)-kGrowBoxSize,
  76.             GetWindowWidth(theWindow)-kGrowBoxSize+1, GetWindowHeight(theWindow)+1);
  77.         SetWindowVScrollBar(theWindow,
  78.             NewControl(theWindow, &vScrollBarRect, "\p", TRUE, 0, 0, 0, scrollBarProc, 0));
  79.         SetWindowHScrollBar(theWindow,
  80.             NewControl(theWindow, &hScrollBarRect, "\p", TRUE, 0, 0, 1000, scrollBarProc, 0));
  81.         
  82.         GetTERect(theWindow, &destRect, TRUE);
  83.         viewRect=destRect;
  84.         destRect.right+=1000;
  85.         hTE=TENew(&destRect, &viewRect);
  86.         SetWindowTE(theWindow, hTE);
  87.         TextFont((**hTE).txFont=geneva);
  88.         TextSize((**hTE).txSize=9);
  89.         TextFace((**hTE).txFace=0);
  90.         GetFontInfo(&theFontInfo);
  91.         (**hTE).fontAscent=theFontInfo.ascent;
  92.         (**hTE).lineHeight=theFontInfo.ascent+theFontInfo.descent+theFontInfo.leading;
  93.         AdjustViewRect(hTE);
  94.         TEAutoView(TRUE, hTE);
  95.         (**hTE).clickLoop=gClickLoopUPP;
  96.         PutDataIntoTEFields(theWindow);
  97.     }
  98.     
  99.     SetWindowIsActive(theWindow, TRUE);
  100.     AdjustVScrollBar(GetWindowVScrollBar(theWindow), hTE);
  101.     AdjustMenus();
  102. }
  103.  
  104. void KeyPressedInBuildWindow(WindowPtr theWindow, unsigned char theChar)
  105. {
  106.     TEHandle        hTE;
  107.     ControlHandle    vScrollBar;
  108.     short            lineNum;
  109.     
  110.     hTE=GetWindowTE(theWindow);
  111.     vScrollBar=GetWindowVScrollBar(theWindow);
  112.     
  113.     switch (theChar)
  114.     {
  115.         case key_UpArrow:
  116.             if (AnyHighlightedQQ(theWindow))
  117.             {
  118.                 lineNum=CurrentLineNumber(hTE);
  119.                 if (lineNum==0)
  120.                     lineNum=TotalNumberOfLines(hTE)-1;
  121.             }
  122.             else lineNum=TotalNumberOfLines(hTE)-1;
  123.             
  124.             HighlightLine(hTE, lineNum-1);
  125.             break;
  126.         case key_DownArrow:
  127.             if (AnyHighlightedQQ(theWindow))
  128.             {
  129.                 lineNum=CurrentLineNumber(hTE);
  130.                 if (lineNum==TotalNumberOfLines(hTE)-2)
  131.                     lineNum=-1;
  132.             }
  133.             else lineNum=-1;
  134.             
  135.             HighlightLine(hTE, lineNum+1);
  136.             break;
  137.         case '\r':
  138.             if (RefHighlightedQQ(theWindow))
  139.                 DoEditRef(theWindow);
  140.             else
  141.                 DoEditInstantiation(theWindow);
  142.             break;
  143.         case 0x08:
  144.             if (RefHighlightedQQ(theWindow))
  145.                 DoDeleteRef(theWindow);
  146.             else
  147.                 DoDeleteInstantiation(theWindow);
  148.             break;
  149.         default:
  150.             break;
  151.     }
  152.     
  153.     AdjustVScrollBar(vScrollBar, hTE);
  154. }
  155.  
  156. void MouseUpInBuildWindow(WindowPtr theWindow, Point thePoint)
  157. {
  158.     TEHandle        hTE;
  159.     
  160.     if (gInProgress)
  161.         return;
  162.     
  163.     hTE=GetWindowTE(theWindow);
  164.     
  165.     if (PtInRect(thePoint, &((**hTE).viewRect)))
  166.     {
  167.         DealWithBuildMouseUp(theWindow, thePoint);
  168.     }
  169. }
  170.  
  171. Boolean MouseClickedInBuildWindow(WindowPtr theWindow, Point thePoint)
  172. {
  173.     short            partCode;
  174.     ControlHandle    theControl;
  175.     short            scrollDistance;
  176.     short            oldSetting;
  177.     ControlActionUPP    scrollActionUPP=NewControlActionProc(ScrollActionProc);
  178.     ControlActionUPP    hScrollActionUPP=NewControlActionProc(HScrollActionProc);
  179.     TEHandle        hTE;
  180.     
  181.     if (gInProgress)
  182.         return TRUE;
  183.     
  184.     hTE=GetWindowTE(theWindow);
  185.     
  186.     if (PtInRect(thePoint, &((**hTE).viewRect)))
  187.     {
  188.         DealWithBuildContentClick(theWindow, thePoint);
  189.         return TRUE;
  190.     }
  191.     else
  192.     {
  193.         partCode=FindControl(thePoint, theWindow, &theControl);
  194.         if (theControl==GetWindowVScrollBar(theWindow))
  195.         {
  196.             switch (partCode)
  197.             {
  198.                 case inThumb:
  199.                     oldSetting=GetControlValue(theControl);
  200.                     partCode=TrackControl(theControl, thePoint, 0L);
  201.                     if (partCode==inThumb)
  202.                     {
  203.                         scrollDistance=oldSetting-GetControlValue(theControl);
  204.                         if (scrollDistance!=0)
  205.                             TEPinScroll(0, scrollDistance*(**hTE).lineHeight, hTE);
  206.                     }
  207.                     break;
  208.                 case inUpButton:
  209.                 case inDownButton:
  210.                 case inPageUp:
  211.                 case inPageDown:
  212.                     partCode=TrackControl(theControl, thePoint, scrollActionUPP);
  213.                     break;
  214.             }
  215.             
  216.             return TRUE;
  217.         }
  218.         else if (theControl==GetWindowHScrollBar(theWindow))
  219.         {
  220.             switch (partCode)
  221.             {
  222.                 case inThumb:
  223.                     oldSetting=GetControlValue(theControl);
  224.                     partCode=TrackControl(theControl, thePoint, 0L);
  225.                     if (partCode==inThumb)
  226.                     {
  227.                         scrollDistance=oldSetting-GetControlValue(theControl);
  228.                         if (scrollDistance!=0)
  229.                             TEPinScroll(scrollDistance, 0, hTE);
  230.                     }
  231.                     break;
  232.                 case inUpButton:
  233.                 case inDownButton:
  234.                 case inPageUp:
  235.                 case inPageDown:
  236.                     partCode=TrackControl(theControl, thePoint, hScrollActionUPP);
  237.             }
  238.         }
  239.     }
  240.     
  241.     return FALSE;
  242. }
  243.  
  244. void DisposeTheBuildWindow(WindowPtr theWindow)
  245. {
  246.     TEHandle        hTE;
  247.     
  248.     hTE=GetWindowTE(theWindow);
  249.     if (hTE!=0L)
  250.     {
  251.         TEDispose(hTE);
  252.         SetWindowTE(theWindow, 0L);
  253.     }
  254. }
  255.  
  256. static    void PutDataIntoTEFields(WindowPtr theWindow)
  257. {
  258.     TEHandle        hTE;
  259.     
  260.     hTE=GetWindowTE(theWindow);
  261.     TESetSelect(0, 0, hTE);
  262.     TEKey(0x00, hTE);
  263.     TEKey(0x08, hTE);
  264. }
  265.